$(document).ready(function() {

	$('#box-slideshow').jcarousel({
        auto: 0,
		scroll: 3,
		animation: 'slow',
	    initCallback: jcarousel_pagination,
		itemFirstInCallback:  jcarousel_selected,
		itemFirstOutCallback: jcarousel_selected_no
    });
    
	function jcarousel_pagination(carousel) {
		$('#box-slideshow-nav a').bind('click', function() {
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).attr("title")));
        return false;
		});
	};
	
	function jcarousel_selected(carousel, obejctli,liindex,listate){	
	     $('#box-slideshow-nav a:nth-child('+ liindex +')').attr("class","selected");
	};

	function jcarousel_selected_no(carousel, obejctli,liindex,listate){
	     $('#box-slideshow-nav a:nth-child('+ liindex +')').removeAttr("class","selected");
	};

	// Return Top
	$('a[href=#top]').click(function(){
		$('html, body').animate({scrollTop:0}, 'slow');
		return false;
	});


	if(screen.width >= '480') {
	  // FancyBox
	  $(".lightbox-inline").fancybox({
		 fitToView	: false,
		 width		: '70%',
		 height		: '70%',
		 autoSize	: true,
		 closeClick	: false,
		 openEffect	: 'fade',
		 closeEffect	: 'fade'
	  });
	}

	// FancyBox
	$(".box-slideshow-action").fancybox({
		closeClick	: false,
		prevEffect	: 'none',
		nextEffect	: 'none',
		helpers	: {
			title	: {
				type: 'outside'
			},
			overlay	: {
				opacity : 0.9,
				css : {
					'background-color' : '#000'
				}
			},
			thumbs	: {
				width	: 50,
				height	: 50
			}
		}
	});

	// Backstage

	$('.calendar-hover, .blog-hover', this).hide();

    $('#backstage li, .column.col-632', this).hover(

    function () {
        $('.calendar-hover, .blog-hover', this).fadeIn();
    }, function () {
        $('.calendar-hover, .blog-hover', this).fadeOut();
    });

	// Isotope / Masonry

	if(screen.width >= '480') {
	
		var $container = $('#list-work');
		
		$container.isotope({
			itemSelector : '.entry',
			filter: '.recent'
		});
		

		$('#filters li a').click(function(){
			var selector = $(this).attr('data-filter');
			$container.isotope({ filter: selector });
			$('#filters li a').removeClass("selected");
			$(this).addClass("selected");
			return false;
		});	

	}
		
	// Slideshows
	
		// Section Slideshows
			
		    $('#section-s-circular-slideshow').cycle({
				fx: 'fade',
			    speed:  850, 
			    timeout: 4000,
			    next: '#next',
			    prev: '#prev',
			    pager:  '#s-slideshow-nav', 
			    pagerAnchorBuilder: function(idx, slide) { 
			    	  var s = idx > 4 ? ' style="display:none"' : '';
		        return '<li><a href="#">&#9679;</a></li>';
			    },
			    before: function () {
					$('#slideshow-name').html(this.name);
					$('#slideshow-title').html(this.title);
					var slideshowlink = $(this).attr("rel");
					$('#slideshow-link').attr("href", slideshowlink);
		        }
			});
			
		    $('#section-s-slideshow').cycle({
			    fx:     'fade', 
			    speed:  850, 
			    timeout: 4000,
		        prev:    '#s-slideshow-prev',
		        next:    '#s-slideshow-next',
			    pager:  '#s-slideshow-nav', 
			    pagerAnchorBuilder: function(idx, slide) { 
			        return '#s-slideshow-nav li:eq(' + idx + ') a'; // Pager
			    }
			});
			
			$('#section-l-slideshow').cycle({
			    fx:     'fade', 
			    speed:  500, 
			    timeout: 6000,
		        prev:    '#l-slideshow-prev',
		        next:    '#l-slideshow-next',
			    pager:  '#l-slideshow-nav', 
			    pagerAnchorBuilder: function(idx, slide) { 
			        return '#l-slideshow-nav li:eq(' + idx + ') a'; // Pager
			    }
			});
			
		    $('.team-item-fact').cycle({
			    fx:     'scrollVert', 
			    speed:  850, 
			    timeout: 0,
				random:  1,
				next:    '#team-item-rotate'
		    });

	
		// Alert
		
		/* 	$("#notification").slideDown(400).delay(1500).slideUp(400); */
		
		// Clear Form
		
			$('.clear').focus(function() {
				$(this).val("");
			});
			
			$('.clear').blur(function() {
				var clearTitle = $(this).attr("title");
				$(this).val(clearTitle);
			});
		
		// Validation
		
			$("#freeform").validate({
				rules: {
					email: {
						required: true,
						email: true
					},
					phone1: {
						required: true,
						digits: true
					},
					name: {
						required: true
					}
				}
			});
			
		// Forms
		
		
		/* Check List */
		
			$('.form-checklist li').click(function(){
				checkBox = $(this);
				checkBox.toggleClass('selected');
				if(checkBox.is('.selected')){
					checkBox.find('input').attr('checked','checked');
				} else {
				checkBox.find('input').removeAttr('checked');
				}
			});
		
		// Hovers / Slides
	
		/* Navigation */
		
		$("#nav-btn").toggle(
			function () {
				$('html, body').animate({scrollTop:0}, '400', function(){
					$("#nav-main").fadeIn(100, function(){
						$("#nav-btn").addClass('selected');
					});
				});
				return false;
				
			}, function () {
				$('html, body').animate({scrollTop:0}, '400', function(){
					$("#nav-main").fadeOut(100, function(){
						$("#nav-btn").removeClass('selected');
					});
				});	
		});
	
		/* Filters Action */
			
		$(".filter-btn").toggle(
			function () {
				$('html, body').animate({scrollTop:0}, '400', function(){
					$("#filter-section").slideDown(400, function(){
						$("#filter-btn").addClass('selected');
					});
				});
				return false;
				
			}, function () {
				$('html, body').animate({scrollTop:0}, '400', function(){
					$("#filter-section").slideUp(400, function(){
						$(".filter-btn").removeClass('selected');
					});
				});	
		});
		
		/* Footer Action */
		
			$("#footer-action-button").toggle(function(){
				$("#footer-action-panel").slideDown();
    			var offset = $($(this).attr('href')).offset().top;
    			$('html, body').animate({scrollTop:offset}, 900);	
			},function(){
				$("#footer-action-panel").slideUp();
			});
	
		/* Boxes */
	
			$(".box-hover").hoverIntent({
					interval: 40,
					over: fadeIn, 
					out: fadeOut
				});
			
			function fadeIn() { $(".box-hover-item", this).fadeIn(400); }
			function fadeOut() { $(".box-hover-item", this).fadeOut(400); }
	
		/* Work & Latest Work Homepage */

		if(screen.width >= '480') {
	
		    $("#list-work, #box-slideshow").hover(
		
		    function() {}, function() {
		        $('#list-work>li, #box-slideshow li').fadeTo("fast", 1.0);
		    });
		
		    $("#list-work>li, #box-slideshow li").hoverIntent(
		
		    function() {
		          
		        $(this).fadeTo("fast", 1.0);
				$('.list-work-info', this).fadeIn(200);
				$('.list-work-hover', this).fadeIn(200);
				$('.list-work-hover', this).css( 'z-index', 10000);
		    }, function() {
				$('.list-work-info', this).fadeOut(200);
				$('.list-work-hover', this).fadeOut(200);
		
		    });
		}
    
	// UI Sliders
	
		$( "#slider-budget" ).slider({
			range: true, 
			min: 300, 
			max: 30000, 
			step: 100,
			values: [ 700, 5000 ],
			slide: function( event, ui ) {
				$( "#budget" ).val( "\u00A3" + ui.values[ 0 ] + " - \u00A3" + ui.values[ 1 ]);
			}
		});
		
		$( "#budget" ).val( "\u00A3" + $( "#slider-budget" ).slider( "values", 0 ) + " - \u00A3" + $( "#slider-budget" ).slider( "values", 1 ));
		
		$( "#slider-deadline" ).slider({
			range: true, 
			min: 1, 
			max: 15, 
			values: [ 2, 12 ],
				slide: function( event, ui ) {
					$( "#deadline" ).val(ui.values[ 0 ] + " Week - " + ui.values[ 1 ] + " Week");
				}
		});
		
		$( "#deadline" ).val($( "#slider-deadline" ).slider( "values", 0 ) + " Week - " + $( "#slider-deadline" ).slider( "values", 1 ) + " Week");
		
		
	// Parallax	
	
		$('a[href=#step-one]').click(function () {
		    $.scrollTo('#step-one', 2200);
		});
		$('a[href=#step-two]').click(function () {
		    $.scrollTo('#step-two', 2200);
		});
		$('a[href=#step-three]').click(function () {
		    $.scrollTo('#step-three', 2200);
		});
		$('a[href=#step-four]').click(function () {
		    $.scrollTo('#step-four', 2200);
		});
	
		/* Scrollorama Plugin */
		var scrollorama = $.scrollorama({ blocks:'.scrollblock', enablePin:false });
		
		/* Step One */
	    $('#step-one-wrap').hide().fadeIn('slow');
		scrollorama.animate('#animate-step-one',{ delay: 0, duration: 300, property:'opacity', start:1 });
		scrollorama.animate('#animate-step-one',{ delay: 20, duration: 300, property:'margin-top', start: -200, pin:false });
		scrollorama.animate('#animate-step-one',{ delay: 100, duration: 300, property:'opacity', end:0 });
		
		/* Step Two */
		scrollorama.animate('#animate-step-two',{ duration: 4000, property:'rotate', start:720 });
		scrollorama.animate('#step-two-wrap',{ delay: 400, duration: 400, property:'opacity', start:0 });
		scrollorama.animate('#step-two-wrap',{ delay: 400, duration: 300, property:'left', start: 0, end:330 });
		
		/* Step Three */
		scrollorama.animate('#step-three-wrap',{ delay: 300, duration: 500, property:'opacity', start:0 });
		scrollorama.animate('#step-three-wrap',{ delay: 300, duration: 500, property:'left', start: 0, end:330 });
		scrollorama.animate('#animate-one',{ delay: 700, duration: 300, property:'opacity', start:0 });
		scrollorama.animate('#animate-one',{ duration: 2000, property:'rotate', start:720 });	
		scrollorama.animate('#animate-two',{ delay: 740, duration: 300, property:'opacity', start:0 });
		scrollorama.animate('#animate-two',{ duration: 2000, property:'rotate', start:720 });	
		scrollorama.animate('#animate-three',{ delay: 770, duration: 300, property:'opacity', start:0 });
		scrollorama.animate('#animate-three',{ duration: 2000, property:'rotate', start:720 });	
		scrollorama.animate('#animate-four',{ delay: 770, duration: 300, property:'opacity', start:0 });
		scrollorama.animate('#animate-four',{ duration: 2000, property:'rotate', start:500 });	
		scrollorama.animate('#animate-five',{ delay: 770, duration: 300, property:'opacity', start:0 });
		scrollorama.animate('#animate-five',{ duration: 2000, property:'rotate', start:720 });
		scrollorama.animate('#animate-six',{ delay: 700, duration: 300, property:'opacity', start:0 });
		scrollorama.animate('#animate-six',{ duration: 2000, property:'rotate', start:720 });
		scrollorama.animate('#animate-seven',{ delay: 700, duration: 300, property:'opacity', start:0 });
		scrollorama.animate('#animate-seven',{ duration: 2000, property:'rotate', start:720 });
			
		/* Step Four */
		scrollorama.animate('#step-four-wrap',{ delay: 300, duration: 500, property:'opacity', start:0 });
		scrollorama.animate('#step-four-wrap',{ delay: 300, duration: 500, property:'left', start: 0, end:330 });
		scrollorama.animate('#animate-step-four',{ delay: 540, duration: 500, property:'margin-top', start: -300, pin:false });
		scrollorama.animate('#animate-step-four',{ delay: 500, duration: 500, property:'opacity', start:0 });
	
});

// Google Route Finder
	    
	var directionDisplay;
	var directionsService = new google.maps.DirectionsService();
	function initialize() {
	var latlng = new google.maps.LatLng(53.530462,-2.504711);
	directionsDisplay = new google.maps.DirectionsRenderer();
	var myOptions = {
	  zoom: 14,
	  center: latlng,
	  mapTypeId: google.maps.MapTypeId.ROADMAP,
	  mapTypeControl: false
	};
	directionsDisplay.setPanel(document.getElementById("directionsPanel"));
	var marker = new google.maps.Marker({
	  position: latlng, 
	  map: map, 
	  title:"My location"
	}); 
	}
	function calcRoute() {
	var start = document.getElementById("routeStart").value;
	var end = "53.530462,-2.504711";
	var request = {
	  origin:start,
	  destination:end,
	  travelMode: google.maps.DirectionsTravelMode.DRIVING
	};
	directionsService.route(request, function(response, status) {
	  if (status == google.maps.DirectionsStatus.OK) {
	    directionsDisplay.setDirections(response);
	  }
	});
	}
	initialize();





